package xmls

var SystemMapper = []byte(`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "https://raw.githubusercontent.com/zhuxiujia/GoMybatis/master/mybatis-3-mapper.dtd">
<mapper>
    <!--logic_enable 逻辑删除字段-->
    <!--logic_deleted 逻辑删除已删除字段-->
    <!--logic_undelete 逻辑删除 未删除字段-->
    <!--version_enable 乐观锁版本字段,支持int,int8,int16,int32,int64-->
    <resultMap id="BaseResultMap" tables="t_system">
      <id column="id" langType="int"/>
	  <result column="leader" langType="string"   />
	  <result column="system_name" langType="string"   />
	  <result column="system_type" langType="string"   />
	  <result column="create_by" langType="string"   />
	  <result column="create_time" langType="Time"   />
	  <result column="update_by" langType="string"   />
	  <result column="update_time" langType="Time"   />
	  <result column="is_delete" langType="int"  logic_enable="true" logic_undelete="0" logic_deleted="1" />
    </resultMap>
	<select id="SelectSystemsByUserId">
		select ts.id id,
		leader,
		system_name,
		system_type,
		ts.create_by create_by,
		ts.create_time create_time,
		ts.update_by update_by,
		ts.update_time update_time
		from t_system ts
		left join t_user_system tus on ts.id = tus.sys_id
		where tus.user_id = #{user_id}
		<if test="system_name != ''">
			and system_name like #{'%'+system_name+'%'}
		</if>
		<if test="system_type != ''">
			and system_type like #{'%'+system_type+'%'}
		</if>
		<if test="leader != ''">
			and leader like #{'%'+leader+'%'}
		</if>
		and ts.is_delete = 0 limit #{current} , #{pageSize}
	</select>

	<select id="GetAllSystemCount">
		select count(1) from t_system where 1=1
		<if test="system_name != ''">
			and system_name like #{'%'+system_name+'%'}
		</if>
		<if test="system_type != ''">
			and system_type like #{'%'+system_type+'%'}
		</if>
		<if test="leader != ''">
			and leader like #{'%'+leader+'%'}
		</if>
		<if test="user_id != 0">
			and id in (select sys_id from t_user_system where user_id = #{user_id})
		</if>
		and is_delete = 0
	</select>

	<select id="GetSystemsByPage">
		select * from t_system where 1=1
		<if test="system_name != ''">
			and system_name like #{'%'+system_name+'%'}
		</if>
		<if test="system_type != ''">
			and system_type like #{'%'+system_type+'%'}
		</if>
		<if test="leader != ''">
			and leader like #{'%'+leader+'%'}
		</if>
		and is_delete = 0
		limit #{current} , #{pageSize}
	</select>

	<deleteTemplate wheres="id?id = #{id}"/>

	<insert id="AddSystem">
		insert into t_system(leader,system_name,system_type,create_by,update_by)
		values (#{leader},#{system_name},#{system_type},'root','root')
	</insert>

	<update id="ModifySystemById">
		update t_system set
		leader=#{leader},system_name=#{system_name},system_type=#{system_type},update_by=#{update_by},update_time=current_timestamp
		where id =#{id} and is_delete =0
	</update>

	<select id="GetUsersBySystemId">
		select * from t_user where id in(
		select user_id
		from t_user_system
		where sys_id = #{id}) and is_delete =0
	</select>

	<selectTemplate wheres="id?id = #{id}">and is_delete =0</selectTemplate>
	<insert id="AddUsersBySystemId">
		insert into t_user_system (user_id,sys_id) values (#{userId},#{id})
	</insert>

	<delete id='DeleteUsersById'>
		delete from t_user_system where sys_id = #{id}
	</delete>
</mapper>`)
